package test.upload;


import java.io.*;
import java.net.Socket;
import java.util.Scanner;

public class Disanti2 {
    public static final String FOLDER = "C:\\Users\\oldliu\\Pictures";

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Socket s = null;
        try {
            s = new Socket("127.0.0.1", 9999);
            InputStream inp = s.getInputStream();
            OutputStream out = s.getOutputStream();
            BufferedReader buff = new BufferedReader(new InputStreamReader(inp));
            PrintWriter pw=new PrintWriter(out,true);
            String s1=in.next();//??
            File file = new File(FOLDER, s1);//???
            if (file.exists()==false||file.canRead()==false){
                //out.write(0);
                System.out.println("没有这个文件");
            }else {
                //out.write(1);
                pw.println(s1);//把文件名发给服务器
                FileInputStream fil = new FileInputStream(file);
                byte[] bytes = new byte[1024];
                int len=0;
                while ((len=fil.read(bytes))>-1){
                    out.write(bytes,0,len);
                }
                out.flush();
                s.shutdownOutput();
                System.out.println(buff.readLine());
                fil.close();
            }
            System.out.println(s+"结束");
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                if (s!=null){
                    s.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
